Skip to content

fix(events): collapse unauthorized-agent list to 404#290

Closed
asherfink wants to merge 1 commit into
mainfrom
asher.fink/fix-events-authz-404
Closed

fix(events): collapse unauthorized-agent list to 404#290
asherfink wants to merge 1 commit into
mainfrom
asher.fink/fix-events-authz-404

Conversation

@asherfink

@asherfink asherfink commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

What

GET /events gates on the parent agent via DAuthorizedQuery, which collapses a denied agent check to 404 — consistent with the other agent-gated routes — so the events filter can't be used to probe cross-tenant agent existence. The integration test still asserted 403; this aligns it with that behavior.

Test

tests/integration/api/events/test_events_authz_api.py::TestEventsAuthzAPIIntegration::test_list_events_unauthorized_agent_returns_404 (renamed from _returns_403) — passes locally alongside the rest of the events authz suite.

Greptile Summary

This PR corrects a stale integration test that was asserting a 403 response for an unauthorized-agent query on GET /events, when the production code already collapses that denial to 404 via DAuthorizedQuery_check_agent_or_collapse_to_404.

  • Renames test_list_events_unauthorized_agent_returns_403_returns_404 and updates the assert response.status_code from 403 to 404.
  • Removes the now-incorrect docstring that cited the "403 convention" and replaces it with an inline comment explaining the cross-tenant probe-prevention rationale.

Confidence Score: 5/5

Safe to merge — the single changed test now correctly reflects the 404 behavior already enforced by the production authorization helper.

The fix is confined to one test assertion. The production path through DAuthorizedQuery → _check_agent_or_collapse_to_404 has been returning 404 for denied agents, so updating the test to match closes a gap where the test was silently not exercising the real behavior.

No files require special attention.

Important Files Changed

Filename Overview
agentex/tests/integration/api/events/test_events_authz_api.py Single test corrected: assertion updated from 403 → 404 to match the actual behavior of DAuthorizedQuery for agent resources, and docstring referencing the old convention removed.

Sequence Diagram

sequenceDiagram
    participant Client
    participant EventsRouter as GET /events
    participant DAuthorizedQuery
    participant CheckAgent as _check_agent_or_collapse_to_404
    participant AuthService as AuthorizationService
    participant Exception as ItemDoesNotExist (404)

    Client->>EventsRouter: "GET /events?task_id=X&agent_id=Y"
    EventsRouter->>DAuthorizedQuery: resolve agent_id dependency
    DAuthorizedQuery->>CheckAgent: check agent Y (read)
    CheckAgent->>AuthService: authorization.check(agent Y, read)
    AuthService-->>CheckAgent: AuthorizationError (denied)
    CheckAgent->>Exception: raise ItemDoesNotExist
    Exception-->>Client: HTTP 404
Loading

Reviews (1): Last reviewed commit: "fix(events): collapse unauthorized-agent..." | Re-trigger Greptile

The list_events route gates on the parent agent via DAuthorizedQuery, which
collapses a denied agent check to 404 — consistent with the other agent-gated
routes — so the events filter can't be used to probe cross-tenant agent
existence. Align the integration test, which still asserted 403, with this
behavior.
@asherfink asherfink requested a review from a team as a code owner June 9, 2026 03:02
@asherfink

Copy link
Copy Markdown
Contributor Author

Nvm this was already fixed in #291

@asherfink asherfink closed this Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants